local _G = GLOBAL

-- 是否是游戏原生基础料理(料理名,是否是大厨料理)
function PASTORAL_TOOL_IsNativeCookingProduct(name, ismaster)
    -- 普通料理
    if not ismaster then
        for k, v in pairs(require("preparedfoods")) do
            if name == v.name then
                return true
            end
        end
    end
    -- 大厨料理
    for k, v in pairs(require("preparedfoods_warly")) do
        if name == v.name then
            return true
        end
    end
    return false
end

-- 注册贴图集
PASTORAL_RegisterInventoryItemAtlas = function(atlas_path)
    local atlas = resolvefilepath(atlas_path)

    local file = io.open(atlas, "r")
    local data = file and file:read("*all") or ""
    if file then
        file:close()
    end

    local str = string.gsub(data, "%s+", "")
    local _, _, elements = string.find(str, "<Elements>(.-)</Elements>")

    for s in string.gmatch(elements, "<Element(.-)/>") do
        local _, _, image = string.find(s, "name=\"(.-)\"")
        if image ~= nil then
            RegisterInventoryItemAtlas(atlas, image)
            RegisterInventoryItemAtlas(atlas, hash(image)) -- for client
        end
    end
end


GLOBAL.PASTORAL_TOOL_IsNativeCookingProduct = PASTORAL_TOOL_IsNativeCookingProduct
GLOBAL.PASTORAL_RegisterInventoryItemAtlas = PASTORAL_RegisterInventoryItemAtlas
